package com.bakerj.infinitecards.transformer;

import com.bakerj.infinitecards.AnimationTransformer;

import ohos.agp.components.Component;

/**
 * DefaultTransformerToBack
 *
 * @author BakerJ
 * @since : 2021.5.24
 */
public class DefaultTransformerToBack implements AnimationTransformer {
    @Override
    public void transformAnimation(Component view, float fraction, int cardWidth, int cardHeight,
                                    int fromPosition, int toPosition) {
        int myFromPosition = toPosition + 1;
        int positionCount = myFromPosition - toPosition;
        float scale = (float) ((0.8F - 0.1F * (double)myFromPosition) + (0.1F * (double)fraction * (double)positionCount));
        view.setScaleX(scale);
        view.setScaleY(scale);
        float setTranslationY = (float)((double)(-cardHeight) * (0.8F - (double)scale) * 0.5F - (double)cardWidth * 0.02F
                * (double)fromPosition + (double)cardHeight * (double)fraction);
        view.setTranslationY(setTranslationY);
        view.setAlpha(fraction);
    }

    @Override
    public void transformInterpolatedAnimation(Component view, float fraction, int cardWidth,
                                                int cardHeight, int fromPosition, int toPosition) {
    }
}
